package com.kgc.sbt.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaModel;
import com.aliyun.teaopenapi.models.Config;


/**
 * @Classname Sample
 * @Description TODO
 * @Date 2021/6/19 11:01
 * @Created by 190120
 */

public class Sample {
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static String smsSign(String phone,int code) {
        com.aliyun.dysmsapi20170525.Client client = null;
        try {
            client = Sample.createClient("LTAI4GGZNkTS6xMsDGXqo369", "GJTJdCwfidG1EYCllgUPAiFrV9FbiU");
        } catch (Exception e) {
            e.printStackTrace();
        }
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phone)
                .setSignName("南京紫码装饰工程有限公司")
                .setTemplateCode("SMS_212707226")
                .setTemplateParam("{\"code\":\""+code+"\"}");
        SendSmsResponse resp = null;
        try {
            resp = client.sendSms(sendSmsRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
